package org.jeecg.modules.zonglzp.controller;

import com.alibaba.fastjson.JSONObject;
import org.jeecg.modules.zonglzp.service.MeasuringService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/measuring")
public class MeasuringController {

    @Autowired
    MeasuringService service;
    /*
       查看这个订单中这个小产品的量体数据
     */
    @GetMapping("/liangtidetail")
    public JSONObject getliangtidetail(
            @RequestParam(name = "smallproductId") String smallproductId,
            @RequestParam(name = "teamorderSn") String teamorderSn
    ) {
        JSONObject obj = new JSONObject();
        List<Map<String, String>> mapList=new ArrayList<Map<String, String>>();

         //取得备注和图片
        HashMap<String,String> remarkandimg=service.getremarkandimg(smallproductId);
        String imgs[]= remarkandimg.get("liangti_imgs").split(",");


        //先查询是不是标准
        int bodysType=service.getbodysType(smallproductId,teamorderSn);
         if(bodysType==1){
            String standardSize=service.getstandardSize(smallproductId,teamorderSn);
            Map<String,String> map = new HashMap<String, String>();
             map.put("body_sizename","标准尺码");
             map.put("bodysize_value",standardSize);
             mapList.add(map);
             obj.put("data", mapList);
             obj.put("imgs", imgs);
             obj.put("liangtiremark", remarkandimg.get("liangti_remark"));
             return obj;
         }

        mapList = service.getliangtidetail(smallproductId, teamorderSn);
        obj.put("liangtiremark", remarkandimg.get("liangti_remark"));
        obj.put("data", mapList);
        obj.put("imgs", imgs);
        return obj;
    }
}
